#pragma once

#include <time.h>

#ifdef  WIN32
#include <Windows.h>
#endif

struct Cosmetic3DTryon_TimeCnt
{
    double st, et;
    int iTickCnt;
    double MSSum;

    double getMs() {
        #ifdef  WIN32
        LARGE_INTEGER stime;
        LARGE_INTEGER proc_freq;
        QueryPerformanceCounter(&stime);
        QueryPerformanceFrequency(&proc_freq);
        return (double)stime.QuadPart / (double)proc_freq.QuadPart * 1000;
        #else
        double cur = clock() / 1000.0;
        return cur;
        #endif
    }

    void Init() {
        iTickCnt = 0;
        MSSum = 0;
    }

    void CalTimeStart() {
        //st = GetTickCount();
        st = getMs();
    }

    double CalTimeEnd() {
        //et = GetTickCount();
        et = getMs();
        iTickCnt++;
        MSSum = MSSum + ( et - st );
        return (et - st);
    }

    float CalAverTime() {
        return (float)(MSSum) / (float)(iTickCnt + 0.0000001 );
    }
    float CalAverTime(int i) {
        return (float)(MSSum) / (float)(i + 0.0000001 );
    }
};
